<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
<meta http-equiv="Content-Style-Type" content="text/css"/>
<meta name="google-site-verification" content="6Yn0h284wKFifrdTx677AUnmiESipe5ng2eETm63Qck" />
<title>
 <?php
// error_reporting(E_ALL);
    require_once "scripts/formfunc.php";
    if ( is_404() ) {
        bloginfo('name'); ?> | 404 Nothing Found <?php
    }
    else {
        bloginfo('name'); ?> | <?php bloginfo('description');
    }
?>
</title>

<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
 <link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS Feed" href="<?php bloginfo('rss2_url'); ?>" />
 <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
<script src="/js/oneb1.js" type="text/javascript"></script>
<script src="/js/mem-rvw.js" type="text/javascript"></script>
</head>
<body>
<div id='container'>
    <div id='header'>
<?php
// ---------------------------------------
// first handle actions
// ---------------------------------------

global $context;

$email              = @$_POST['usr'];
$pwd                = @$_POST['pwd'];
$isreset            = (isset($_POST['chkreset']));
$siteurl            = get_bloginfo("url");
$logout             = @$_GET['logout'];

var_dump($_POST);

$alert              = "";

if(isset($logout)) {
    $context->Logout();
}

// if reset, context->send the email and stay here.
// The email will link to site/registration?resetkey
if($isreset) {
    if(empty($email)) {
        $alert = "Please enter your login email to be reset.";
    }
    else {
        /*
        if(! $context->EmailExists($email)) {
            $alert = '"'.$email.'" is not a member email.';
        }
        */
        // else {
            $context->SendResetEmail($email);
            $alert = "Check your email to reset your password.";
        // }
    }
}

else {
    // usr and pwd only avail if not logged in
    if(empty($email) || empty($pwd)) {
        
    }
    else {
        if(! $context->TryLogin($email, $pwd)) {
            $alert = "Invalid login.";
        }
    }
}

echo "<div id='login'>\n";

// ---------------------------------------
// display login form if not logged in
// ---------------------------------------

if(! $context->IsLoggedIn()) {
    // href='{$siteurl}/forgot_password'>Forgot password</a>
    $forgot_link = $siteurl ."?forgot-password";
    echo "<form id='form-login' name='form-login' action='' method='post'>
            <label for='submit'>Member Sign In</label>
            <input type='submit' name='submit' value='' class='submit-link'/>
            <input name='usr' id='usr' type='text'
                class='input-text' value = 'email' size='15'/>
            <input name='pwd' id='pwd' type='text'
                class='input-text' value = 'password' size='15'/>
            <input name='alert' id='alert' type='hidden' value='$alert'/>
            <a class='submit-link' style='margin-right: 2em'
                href='{$siteurl}/registration'>Become a Member</a>
                <br/>\n";
    listCheckBox("chkreset", "Reset password", false);
    echo "</form>\n";
}
else {
    echo "
    <div id='logged-in'>
    ";
    echo "
    <a href='{$siteurl}?logout=1'>Sign out {$context->UserName()}</a>
    ";
    if($context->IsUserPending()) {
        echo "&nbsp;(Membership Pending)";
    }
    echo "
    </div>\n";
}
echo "</div>\n";

echo "
    <h1>OneBainbridge</h1>
    <h2>Everyone at the table. Sharing information.</h2>
    <h2>Working together. Helping each other.</h2>

    </div><!--end header-->

    <ul id='nav' class='nav'>
        <li><a href='{$siteurl}/daily'>BainbridgeDaily</a></li>
        <li><a href='{$siteurl}/townmeeting'>TownMeeting</a></li>
        <li><a href='mailto://admin@onebainbridge.org'>Contact</a></li>
    </ul>
<!-- leaving container open for the footer to resolve -->
";
?>
